﻿using System.Collections;
using System.Linq;
using UnityEngine;

namespace cframework_coroutineutil
{
    public class WaitAny : WaitBase
    {
        public int finishedIndex = -1;

        public override bool keepWaiting
        {
            get
            {
                var a = results.All(t => !t.finished);
                if (!a)
                {
                    StopAllCoroutine();
                }
                return a;
            }
        }

        public WaitAny(params IEnumerator[] coroutines) : base(coroutines)
        {

        }

        public WaitAny(MonoBehaviour monoBehaviour, params IEnumerator[] coroutines) : base(monoBehaviour, coroutines)
        {
            
        }

        protected override IEnumerator Wrapper(IEnumerator e, int index)
        {
            yield return base.Wrapper(e, index);
            finishedIndex = index;
        }
    }
}